package com.sunyur.tailor.channel.service.inner.supplier.service.impl;

import com.alibaba.fastjson.JSON;
import com.sunyur.tailor.channel.common.inner.base.SunyurResult;
import com.sunyur.tailor.channel.common.middle.enums.MiddleResultEnum;
import com.sunyur.tailor.channel.service.inner.base.SunyurEventService;
import com.sunyur.tailor.channel.service.inner.supplier.param.SupplierByCodeParam;
import com.sunyur.tailor.channel.service.middle.supplier.MiddleSupplierService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

/**
 *
 * @Author 99288
 * @Description 供应商入口类
 * @Param
 * @return
**/
public class SupplierEntranceServiceImpl implements SunyurEventService {
    private static final Logger LOGGER_INFO = LoggerFactory.getLogger(SupplierEntranceServiceImpl.class);
    private static final Logger LOGGER_ERROR = LoggerFactory.getLogger(SupplierEntranceServiceImpl.class);

    @Autowired
    MiddleSupplierService middleSupplierService;

    public SunyurResult<Boolean> update(String param) throws Exception {
        LOGGER_INFO.info("SupplierEntranceServiceImpl update param:{}", param);
        SunyurResult<Boolean> result = new SunyurResult<>();
        if(StringUtils.isBlank(param)){
            result.setErrorMessage(MiddleResultEnum.PARAM_NULL.getCode(), MiddleResultEnum.PARAM_NULL.getValue());
        }else{
            SupplierByCodeParam supplierByCodeParam = JSON.parseObject(param, SupplierByCodeParam.class);
            result = middleSupplierService.syncSupplier(supplierByCodeParam);
        }
        LOGGER_INFO.info("SupplierEntranceServiceImpl update return:{}", JSON.toJSONString(result));
        return result;
    }
}
